package com.andy.buyu.server.action;

import org.springframework.stereotype.Component;

import com.andy.buyu.server.game.GameUser;
import com.andy.buyu.server.game.Global;
import com.andy.buyu.server.game.Room;
import com.andy.buyu.server.socket.GmAction;
import com.andy.buyu.server.socket.MySocketSession;
import com.andy.buyu.server.socket.SendUtil;
import com.andy.buyu.server.socket.codec.DataWrap;
import com.andy.buyu.server.utils.GoConstant;

/**
 * 预占位逻辑
 * @author cuiwm
 *
 */
@Component(GmAction.ACTION_PREFIX+GmAction.ACTION_110)
public class Action110 implements IReqAction{

	@Override
	public void doAction(MySocketSession session, DataWrap data) {
		GameUser user = session.getUser();
		int desk = data.getInt();
		int index = data.getByte();
		if(index < GoConstant.CHAIR_SIZE){
			Room room = Global.getRoom(desk);
			if(room == null) return;
			boolean isOk = false;
			synchronized (room) {
				isOk = room.preEnter(user,index);
			}
			if(isOk){
				SendUtil.send110(session, desk,index);
			}else{
				SendUtil.send110(session,-1, -1);
			}
		}
		
	}


	
	
	
}
